--|| ***************************************************************************************************************** [[
--|| PROJECT:       MTA Ingame Handling Editor
--|| FILE:          functions/hDefaultDo.lua
--|| DEVELOPERS:    Qais <qaisjp@gmail.com> <qaispatankar@hotmail.co.uk>
--|| PURPOSE:       Default handling reciever
--||
--|| COPYRIGHTED BY QAIS
--|| YOU ARE NOT ALLOWED TO MAKE MIRRORS OR RE-RELEASES OF THIS SCRIPT WITHOUT PERMISSION FROM THE OWNERS
--|| THIS RESOURCE HAS BEEN UPLOADED TO COMMUNITY.MTASA.COM
--|| ***************************************************************************************************************** ]]
local defaultHandling = {}
--[[
Example for XML: <modelHandling suspensionForceLevel="1.2" turnMass="1900" .. centerOfMass="0, 0.2, -0.3"> 500 </modelHandling>
-----------------<............. vehicleProperty="value" ...............................................> modelID </--------->
Syntax: table/string getVehicleDefaultHandling( vehicle/number modelID, string property)
Returns a table if the property value is not passed and success
Returns an unkown value if property value is passed (it shouldnt be NIL)
Returns nil if failed (invalid property/modelID passed).
]]

addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
	function()
		start = getTickCount()
		-- Original Default Handling
		defaultHandling[400] = getOrginalHandling(400)
		defaultHandling[611] = getOriginalHandling(611)
		for i=400, 611 do
			defaultHandling[i] = getOriginalHandling(i)
		end
		-- XML Import Default Handling
		if fileExists(getResourceName(getThisResource())..":config/defaults.xml") then
			local st = getTickCount()
			local xmlNode = xmlLoadFile("config/defaults.xml")
			for number,node in ipairs(xmlNodeGetChildren(xmlNode)) do
				defaultHandling[xmlNodeGetValue(node)] = getNodeGetAttributes(node)
			end
			xmlUnloadFile(xmlNode)
			outputDebugString(getResourceName(getThisResource())"/ :- XML Import process took "..tostring(getTickCount() - st).." milliseconds")
		end
		outputDebugString(getResourceName(getThisResource())"/ :- Initialise process took "..tostring(getTickCount() - start).." milliseconds")
	end
)

function getDefaultHandling(...)
	local start= getTickCount()
	local args = {...}
	local model
	if args[1] then
		if isElement(args[1]) then
			if getElementType(args[1]) == "vehicle" then
				model = getVehicleModel(args[1])
			end
		elseif tonumber(args[1]) then
			model = tonumber(args[1])
		end
	end
	outputDebugString(getResourceName(getThisResource())"/ :- Function process took "..getTickCount() - start.." milliseconds")
	if args[2] and defaultHandling[model] then
		if not defaultHandling[model[args[2]][1] then
			return defaultHandling[model][args[2]]
		elseif defaultHandling[model][args[2]][1] then
			return defaultHandling[model][args[2]][1]..defaultHandling[model][args[2]][2]..defaultHandling[model][args[2]][3]
		end
		return nil
	end
	if defaultHandling[model] then
		return defaultHandling[model]
	end
	return nil
end
